package csel.controller.commands;

import csel.model.*;
import csel.view.*;

public class DropCommand implements GameCommand
{
	private Inventory inventory;
	private Item[] items;

	//Creates the instance of the drop command and gets all the information it will need when it runs
	public DropCommand(Model model, StatusViewport statusViewport)
	{
		this.inventory = model.getPlayerEntity().getInventory();
		this.items = statusViewport.getSelectedInventoryItems();
	}

	//when executed it iterates over all of the items and drops them from the inventory
	public void execute()
	{
		if (items != null)
		{
			if(Model.infoMode)System.out.println("[MODEL] A drop command has been called on " + items.getClass().getSimpleName());
			for (Item i : items)
			{
				if (i instanceof UseableItem)
				{
					if(Model.infoMode)System.out.println("[MODEL] the Drop command has been called on " + i.getTypeId());
					inventory.dropUseableItem((UseableItem) i);
				} else if (i instanceof EquippableItem)
				{
					inventory.dropEquippableItem((EquippableItem) i);
					if(Model.infoMode)System.out.println("[MODEL] the Drop command has been called on " + i.getTypeId());
				}
			}
		}
	}
	
	public String toString()
	{
		return this.getClass().getSimpleName();
	}
}